#pragma once

class Mutex
{
	CRITICAL_SECTION m_crit;

	Mutex(const Mutex&) { }
	void operator = (const Mutex&) { }
public:
	Mutex() { InitializeCriticalSection(&m_crit); }
	~Mutex() { LeaveCriticalSection(&m_crit); }

	void Acquire() { EnterCriticalSection(&m_crit); }
	void Release() { LeaveCriticalSection(&m_crit); }
};

template<typename T>
class ScopeLock
{
	T& m_lock;
	ScopeLock(const ScopeLock& l) : m_lock(l.m_lock) {
	}

	void operator = (const ScopeLock& lock) {
	}

public:
	ScopeLock(T& lock) : m_lock(lock) {
		m_lock.Acquire();
	}

	~ScopeLock() {
		m_lock.Release();
	}
};

#define MUTEX_LOCK(lock) ScopeLock<Mutex> __sl ## lock(lock);